//业务员我的
var app = getApp();
var Api = require("../../../api/method.js");
var Utils = require("../../../utils/util.js");
Page({
  /**
   * 页面的初始数据
   */
  data: {
    nickName: "",
    orderList:"",
    balance:"",
    pop:true,
    inp1:"",
    inp2:""
  },
  //点击弹框
  logo: function (e) {
    this.setData({
      pop: false
    })
  },
  //隐藏白条弹框
  hideBaitiaoView: function (e) {
    if (e.target.dataset.target == 'self')
      this.setData({
        pop: true
      })
  },
  //提现
  Cashwithdrawal: function (e) {
    console.log(e);
    wx.navigateTo({
      url: "/pages/Salesman/withdraw/withdraw?accountBalance=" + e.target.dataset.accountbalance,
    })
  },
  //跳转页面详情
  Details: function (e) {
    wx.navigateTo({
      url: "/pages/branch/Details/Details?id=" + e.currentTarget.dataset.id,
    })
  },
  //点击抽成比例
  bili:function(){
    wx.showToast({
      title: '加载中',
      icon: 'loading'
    });
    let that = this;
    let list={
      branchId: wx.getStorageSync("user").branchId
    }
    Api.viewBranchRate(list,function(err,res){
      console.log(res.data)
      if(res.data.code == 0){
        wx.showToast({ 
            icon: "none",
          duration: 1500,
          title: `${res.data.message}`
        })
        that.setData({
          pop: true
        })
      }else{
        let firstRate = res.data.data.firstRate;
        let secondRate = res.data.data.secondRate;
        that.setData({
          pop: false,
          inp1: firstRate,
          inp2: secondRate
        }) 
      }
      wx.hideLoading();
    })
   
  },
  Number:function(e){
    if (e.detail.value>=26){
      wx.showToast({
        title: '一级推广比例不能大于25%',
        icon: 'none',
        duration: 2000
      })
    }else{
      this.setData({
        inp1: e.detail.value
      })
    }
    
  },
  Number1: function (e) {
    if (e.detail.value >= 26) {
      wx.showToast({
        title: '二级推广比例不能大于25%',
        icon: 'none',
        duration: 2000
      })
    } else {
      this.setData({
        inp2: e.detail.value
      })
    }
   
  },
  //修改分院比率
  ok:function(){
    wx.showToast({
      title: '加载中',
      icon: 'loading'
    });
    let that = this;
    if (that.data.inp1>=26 || that.data.inp2 >=26){
      wx.showToast({
        title: '推广比例不能大于25%',
        icon: 'none',
        duration: 2000
      })
    }else{
    let list = {
      firstRate:that.data.inp1,
      secondRate:that.data.inp2
    }
    console.log(that.data.inp1)
    Api.editBranchRate(list, function (err, res) {
        console.log(res)
        if(res.data.code == 0){
          wx.showToast({
            icon: "none",
            duration: 1500,
            title: `${res.data.message}`
          })
        }else{
          that.setData({
            pop: true
          }) 
          
        }
      wx.hideLoading();
    })
    }
  },
  //分院我的
  branchOwner:function(e){
    let that = this;
    let list = {
    };
    console.log(list);
    Api.branchOwner(list, function (err, res) {
        console.log(res.data);
        if(res.data.code == 1){
          that.setData({
            orderList: res.data.data.orderList,
            nickName:res.data.data.nickName,
            balance: res.data.data.balance
          })
        }
    });
  },
  //分院订单详情
  branchorderList: function () {
    wx.showToast({
      title: '加载中',
      icon: 'loading'
    });
    let that = this;
    let list = {
      branchId: wx.getStorageSync("user").branchId,
      pageNo: 1,
      pageSize: 20
    };
    Api.branchorder(list, function (err, res) {
      console.log(res.data)
      if (res.data.code == 1) {
        let ar = res.data.data;
        for (var i = 0; i < ar.length; i++) {
          ar[i].createdAt = Utils.chinesetime((ar[i]).createdAt, 'Y-M-D h:m')
        }
        that.setData({
          orderList: ar
        })
      }
      wx.hideLoading();
    })
  },
  //取消
  close:function(){
    this.setData({
      pop: true
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.branchOwner();
    this.branchorderList();
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    app.editTabBar1();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
   
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})